package com.cn.kabalifeuser.ui.my.fragment;

import com.cn.kabalifeuser.api.Api;
import com.cn.kabalifeuser.base.BasePresenter;
import com.cn.kabalifeuser.callback.CacheCallBack;
import com.cn.kabalifeuser.config.Constants;
import com.cn.kabalifeuser.ui.my.bean.CouponListBean;
import com.cn.kabalifeuser.ui.my.bean.CouponTypeListBean;
import com.cn.kabalifeuser.ui.my.bean.MyCouponListBean;
import com.cn.kabalifeuser.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * Created by 晓林 on 2020/9/7.
 * function:
 */
public class CardrollPresenter extends BasePresenter<CardrollView> {
    /**
     * 优惠券类型
     *
     * @param token
     */
    public void onCouponTypeData(String token) {
        OkGo.<CouponTypeListBean>get(Api.API_COUPON_TYPE)
                .headers("token", token)
                .execute(new CacheCallBack<CouponTypeListBean>() {
                    @Override
                    public void onSuccess(Response<CouponTypeListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("类型：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onCouponTypeSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    /**
     * 列表
     *
     * @param token
     * @param pid
     * @param page
     * @param limit
     */
    public void onCouponListData(String token, int pid, int status, int page, int limit) {
        OkGo.<MyCouponListBean>get(Api.API_COUPON_MY_LIST)
                .headers("token", token)
                .params("status", status)
                .params("limit", limit)
                .params("page", page)
                .params("pid", pid)
                .execute(new CacheCallBack<MyCouponListBean>() {
                    @Override
                    public void onSuccess(Response<MyCouponListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("list：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onCouponListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }
}
